package com.changhongit.order.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.changhongit.order.config.ResultModel;
import com.changhongit.order.entity.MaterialDetailEntity;
import com.changhongit.order.logger.SystemLogger;
import com.changhongit.order.model.MaterailReq;
import com.changhongit.order.service.InvoceJdbcService;

@Api(tags = "发票管理模块")
@RestController
@RequestMapping("/invoce")
public class InvoceController {
    @Autowired
    InvoceJdbcService invoceJdbcService;


    @SystemLogger
    @ApiOperation(value = "采购订单管理系统-发票管理模块调用采购系统查询订单信息",response = MaterialDetailEntity.class)
    @PostMapping(value = "/rule1")
    public HttpEntity<?> getRule1(@RequestBody MaterailReq params){
        ResultModel<List<MaterialDetailEntity>> resultModel = new ResultModel<>();
        try {
            List<MaterialDetailEntity> rele = invoceJdbcService.findRule(params);
            resultModel.success(rele);
        } catch (Exception e) {
            resultModel.error("采购订单管理系统-发票管理模块调用采购系统查询订单信息，接口出错：" + e.getMessage());
            return new ResponseEntity<>(resultModel, HttpStatus.BAD_REQUEST);
        }
        return new ResponseEntity<>(resultModel, HttpStatus.OK);
    }

    @SystemLogger
    @ApiOperation(value = "物料查询接口2",response = MaterialDetailEntity.class)
    @PostMapping(value = "/rule2")
    public HttpEntity<?> getRule2(@RequestBody MaterailReq params){
        ResultModel<List<MaterialDetailEntity>> resultModel = new ResultModel<>();
        try {
            List<MaterialDetailEntity> rele = invoceJdbcService.findRule(params);
            resultModel.success(rele);
        } catch (Exception e) {
            resultModel.error("采购订单管理系统-发票管理模块调用采购系统查询订单信息，接口出错：" + e.getMessage());
            return new ResponseEntity<>(resultModel, HttpStatus.BAD_REQUEST);
        }
        return new ResponseEntity<>(resultModel, HttpStatus.OK);
    }

    @SystemLogger
    @ApiOperation(value = "物料查询接口3",response = MaterialDetailEntity.class)
    @PostMapping(value = "/rule3")
    public HttpEntity<?> getRule3(@RequestBody MaterailReq params){
        ResultModel<List<MaterialDetailEntity>> resultModel = new ResultModel<>();
        try {
            List<MaterialDetailEntity> rele = invoceJdbcService.findRule(params);
            resultModel.success(rele);
        } catch (Exception e) {
            resultModel.error("采购订单管理系统-发票管理模块调用采购系统查询订单信息，接口出错：" + e.getMessage());
            return new ResponseEntity<>(resultModel, HttpStatus.BAD_REQUEST);
        }
        return new ResponseEntity<>(resultModel, HttpStatus.OK);
    }


    @SystemLogger
    @ApiOperation(value = "物料查询接口4",response = MaterialDetailEntity.class)
    @PostMapping(value = "/rule4")
    public HttpEntity<?> getRule4(@RequestBody MaterailReq params){
        ResultModel<List<MaterialDetailEntity>> resultModel = new ResultModel<>();
        try {
            List<MaterialDetailEntity> rele = invoceJdbcService.findRule(params);
            resultModel.success(rele);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel.error("采购订单管理系统-发票管理模块调用采购系统查询订单信息，接口出错：" + e.getMessage());
            return new ResponseEntity<>(resultModel, HttpStatus.BAD_REQUEST);
        }
        return new ResponseEntity<>(resultModel, HttpStatus.OK);
    }

    @SystemLogger
    @ApiOperation(value = "用户自定义查询",response = MaterialDetailEntity.class)
    @PostMapping(value = "/customize")
    public HttpEntity<?> getRule5(@RequestBody MaterailReq params){
        ResultModel<List<MaterialDetailEntity>> resultModel = new ResultModel<>();
        try {
            List<MaterialDetailEntity> rele = invoceJdbcService.findRule(params);
            resultModel.success(rele);
        } catch (Exception e) {
            resultModel.error("采购订单管理系统-发票管理模块调用采购系统查询订单信息，接口出错：" + e.getMessage());
            return new ResponseEntity<>(resultModel, HttpStatus.BAD_REQUEST);
        }
        return new ResponseEntity<>(resultModel, HttpStatus.OK);
    }
}
